package com.asman.vr.network

import android.app.Application
import com.asman.vr.dto.*
import java.util.concurrent.Executor
import java.util.concurrent.Executors

/**
 * default implementation of ServiceLocator that uses production endpoints.
 * 使用生产端点的ServiceLocator的默认实现。
 */
open class DefaultServiceLocator(val app: Application) : ServiceLocator {
    private val diskIO = Executors.newSingleThreadExecutor()

    private val networkIO = Executors.newFixedThreadPool(5)

    private val api by lazy {
        ApiService.create(Api::class.java)
    }

    private val workApi by lazy {
        ApiWorkerService.create(ApiWorker::class.java)
    }

    override fun getNetworkExecutor(): Executor = networkIO

    override fun getDiskIOExecutor(): Executor = diskIO

    override fun getMainApi() = api

    override fun getWorkerApi() = workApi

    override fun getProjectRepository() =
        ProjectRepository(getMainApi(), getWorkerApi(), getNetworkExecutor())

    override fun getAccountRepository() = AccountRepository(getMainApi(), getWorkerApi(),getNetworkExecutor())

    override fun getAddressRepository() = AddressRepository(getMainApi(), getNetworkExecutor())

    override fun getPayRepository() = PayRepository(getMainApi(), getNetworkExecutor())

    override fun getMessageRepository() = MessageRepository(getMainApi(), getNetworkExecutor())

    override fun getContractRepository() = ContractRepository(getMainApi(), getNetworkExecutor())

    override fun getBaseDataRepository() = BaseDataRepository(getMainApi(), getNetworkExecutor())

    override fun getSchemeRepository(): SchemeRepository =
        SchemeRepository(getMainApi(), getNetworkExecutor())

    override fun getOperateRepository() = OperateRepository(getMainApi(), getNetworkExecutor())

    override fun getCustomMyHomeRepository() =
        CustomMyHomeRepository(getMainApi(), getNetworkExecutor())

    override fun getCommentRepository() = CommentRepository(getMainApi(), getNetworkExecutor())

    override fun getScoreRepository() = ScoreRepository(getMainApi(), getNetworkExecutor())

    override fun getCollectionRepository(): CollectionRepository =
        CollectionRepository(getMainApi(), getNetworkExecutor())

    override fun getDesignerRepository(): DesignerRepository =
        DesignerRepository(getMainApi(), getNetworkExecutor())

    override fun getGoodsDetailRepository() =
        GoodsDetailRepository(getMainApi(), getNetworkExecutor())

    override fun getCallAnswerRepository() =
        CallAnswerRepository(getMainApi(), getNetworkExecutor())

    override fun getCustomerRepository() = CustomerRepository(getMainApi(), getNetworkExecutor())
}